import { Toast, Loading } from "../../../utils/util";
Page({
  data: {
    form: {
      budget: "",
      like: "",
      time: ""
    },
    cityList: [],
    budgetList: [],
    likeList: [],
    timeList: [],
  },
  PickerChange(e) {
    console.log(e)
    this.setData({
      form: {
        ...this.data.form,
        [e.target.dataset.key]: e.detail.value
      }
    })
  },
  async formSubmit() {
    let formDate = this.data.form;
    // for(var i in formDate){
    //   if(formDate[i] == ''){
    //     const msg = i == 'budget' ? '经济预算': i == 'like' ? '景色偏好':'旅游时间';
    //     Toast("none",msg+"不能为空");
    //     return;
    //   }
    // }
    this.getCityList()
  },
  async getCityList() {
    let formDate = this.data.form;
    for (let obj in formDate) {
      if (formDate[obj] == '') {
        delete formDate[obj]
      }
    }
    const res = await wx.cloud.database().collection('cityList').where({
      ...formDate
    }).get()
    this.setData({
      cityList: res.data
    })
  },
  onLoad() {
    this.setData({
      budgetList: wx.getStorageSync('dictList').filter(item => item.dictValue == 'budget')[0]['dictJson'].map(item => item.key),
      likeList: wx.getStorageSync('dictList').filter(item => item.dictValue == 'like')[0]['dictJson'].map(item => item.key),
      timeList: wx.getStorageSync('dictList').filter(item => item.dictValue == 'time')[0]['dictJson'].map(item => item.key),
    })
    this.getCityList()
  }
})